package com.liming.admin.controller;

import com.liming.admin.service.DashboardService;
import com.liming.common.pojo.vo.dashboard.*;
import com.liming.common.result.LMResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author liming
 * @date 2025/3/5
 */
@Slf4j
@RestController
@AllArgsConstructor
@Tag(name = "数据大屏接口-Web")
@RequestMapping("/admin/dashboard")
public class DashboardController {

    private final DashboardService dashboardService;

    @Operation(
            summary = "顶部统计卡片",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = TopCardVO.class))
                    })
            })
    @GetMapping("topCard")
    public LMResult<TopCardVO> topCard() {
        return LMResult.success(dashboardService.topCard());
    }

    @Operation(
            summary = "用户数据顶部统计卡片",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = UserTopCardVO.class))
                    })
            }
    )
    @GetMapping("userTopCard")
    public LMResult<UserTopCardVO> userTopCard() {
        return LMResult.success(dashboardService.userTopCard());
    }

    @Operation(
            summary = "用户注册统计",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = UserRegister.class))
                    })
            })
    @GetMapping("userRegister")
    public LMResult<List<UserRegister>> userRegister(String scope) {
        return LMResult.success(dashboardService.userRegister(scope));
    }

    @Operation(
            summary = "用户性别统计",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = Map.class))
                    })
            })
    @GetMapping("userGender")
    public LMResult<Map<Integer, Long>> userGender() {
        return LMResult.success(dashboardService.userGender());
    }

    @Operation(
            summary = "用户消费排行",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = UserConsumeRankVO.class))
                    })
            })
    @GetMapping("userConsumeRank")
    public LMResult<List<UserConsumeRankVO>> userConsumeRank() {
        return LMResult.success(dashboardService.userConsumeRank());
    }

    @Operation(
            summary = "客户评论顶部统计卡片",
            responses = {
                    @ApiResponse(responseCode = "1", description = "获取成功", content = {
                            @Content(mediaType = "application/json", schema = @Schema(implementation = CustomerReviewTopCardVO.class))
                    })
            })
    @GetMapping("customer_review_top_card")
    public LMResult<CustomerReviewTopCardVO> customerReview() {
        return LMResult.success(dashboardService.customerReviewTopCard());
    }
}
